package com.qolome.dao.mapper;

import static com.qolome.dao.mapper.PasswdBookDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.qolome.dao.model.PasswdBook;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

/**
* Created by Mybatis Generator on 2020/01/05
*/
@Mapper
public interface PasswdBookMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    BasicColumn[] selectList = BasicColumn.columnList(accountId, serverName, accountNumber, accountPassword, type, remark, ownId);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<PasswdBook> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<PasswdBook> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("PasswdBookResult")
    Optional<PasswdBook> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="PasswdBookResult", value = {
        @Result(column="account_id", property="accountId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="server_name", property="serverName", jdbcType=JdbcType.VARCHAR),
        @Result(column="account_number", property="accountNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="account_password", property="accountPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="own_id", property="ownId", jdbcType=JdbcType.VARCHAR)
    })
    List<PasswdBook> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int deleteByPrimaryKey(Long accountId_) {
        return delete(c -> 
            c.where(accountId, isEqualTo(accountId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int insert(PasswdBook record) {
        return MyBatis3Utils.insert(this::insert, record, passwdBook, c ->
            c.map(accountId).toProperty("accountId")
            .map(serverName).toProperty("serverName")
            .map(accountNumber).toProperty("accountNumber")
            .map(accountPassword).toProperty("accountPassword")
            .map(type).toProperty("type")
            .map(remark).toProperty("remark")
            .map(ownId).toProperty("ownId")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int insertMultiple(Collection<PasswdBook> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, passwdBook, c ->
            c.map(accountId).toProperty("accountId")
            .map(serverName).toProperty("serverName")
            .map(accountNumber).toProperty("accountNumber")
            .map(accountPassword).toProperty("accountPassword")
            .map(type).toProperty("type")
            .map(remark).toProperty("remark")
            .map(ownId).toProperty("ownId")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int insertSelective(PasswdBook record) {
        return MyBatis3Utils.insert(this::insert, record, passwdBook, c ->
            c.map(accountId).toPropertyWhenPresent("accountId", record::getAccountId)
            .map(serverName).toPropertyWhenPresent("serverName", record::getServerName)
            .map(accountNumber).toPropertyWhenPresent("accountNumber", record::getAccountNumber)
            .map(accountPassword).toPropertyWhenPresent("accountPassword", record::getAccountPassword)
            .map(type).toPropertyWhenPresent("type", record::getType)
            .map(remark).toPropertyWhenPresent("remark", record::getRemark)
            .map(ownId).toPropertyWhenPresent("ownId", record::getOwnId)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default Optional<PasswdBook> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default List<PasswdBook> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default List<PasswdBook> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default Optional<PasswdBook> selectByPrimaryKey(Long accountId_) {
        return selectOne(c ->
            c.where(accountId, isEqualTo(accountId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, passwdBook, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    static UpdateDSL<UpdateModel> updateAllColumns(PasswdBook record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(accountId).equalTo(record::getAccountId)
                .set(serverName).equalTo(record::getServerName)
                .set(accountNumber).equalTo(record::getAccountNumber)
                .set(accountPassword).equalTo(record::getAccountPassword)
                .set(type).equalTo(record::getType)
                .set(remark).equalTo(record::getRemark)
                .set(ownId).equalTo(record::getOwnId);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(PasswdBook record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(accountId).equalToWhenPresent(record::getAccountId)
                .set(serverName).equalToWhenPresent(record::getServerName)
                .set(accountNumber).equalToWhenPresent(record::getAccountNumber)
                .set(accountPassword).equalToWhenPresent(record::getAccountPassword)
                .set(type).equalToWhenPresent(record::getType)
                .set(remark).equalToWhenPresent(record::getRemark)
                .set(ownId).equalToWhenPresent(record::getOwnId);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int updateByPrimaryKey(PasswdBook record) {
        return update(c ->
            c.set(serverName).equalTo(record::getServerName)
            .set(accountNumber).equalTo(record::getAccountNumber)
            .set(accountPassword).equalTo(record::getAccountPassword)
            .set(type).equalTo(record::getType)
            .set(remark).equalTo(record::getRemark)
            .set(ownId).equalTo(record::getOwnId)
            .where(accountId, isEqualTo(record::getAccountId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: passwd_book")
    default int updateByPrimaryKeySelective(PasswdBook record) {
        return update(c ->
            c.set(serverName).equalToWhenPresent(record::getServerName)
            .set(accountNumber).equalToWhenPresent(record::getAccountNumber)
            .set(accountPassword).equalToWhenPresent(record::getAccountPassword)
            .set(type).equalToWhenPresent(record::getType)
            .set(remark).equalToWhenPresent(record::getRemark)
            .set(ownId).equalToWhenPresent(record::getOwnId)
            .where(accountId, isEqualTo(record::getAccountId))
        );
    }
}